*     *****************************************************************   *;
*     *****************************************************************   *; 
*   Date:          December 27, 2021                               	      *;
*   Authors:       Lisa Dellmuth and Jonas Tallberg				          *;  
*   Purpose: 	   Analyses for book Legitimacy Politics: Elite  		  *;
*    Communication and Public Opinion in Global Governance (CUP, 2023)    *;
*     ****************************************************************    *;
*     ****************************************************************    *;


***************************************
* Fig. 2.1 
***************************************

vers 16.1
capture log close
set more off 

*open and svyset data
******************************************

use TimeSeries_WVS_EVS_1_7_STATA_v20200502.dta

* weighting (post-stratification weights + 1000-equilibrated weight)

svyset [pweight=S018], strata(S009)

rename E069_11 gov
rename E069_20 un 

tab gov
tab gov, nol
ed un S002 if S003==156

gen glgov=.
replace glgov =1 if gov==1|gov==2
replace glgov =0 if gov==3|gov==4

gen glun=.
replace glun =1 if un==1|un==2
replace glun =0 if un==3|un==4

collapse  glgov  glun [pweight=S018], by(S003 S002)
ed

drop if S002==1| S002==2

compress

save wvs1_7_weightedcountry_percgreatalot_wide.dta, replace
 

preserve
keep if io=="gov"
collapse (mean) gl, by(wave) 
save govmean.dta

preserve
keep if io=="un"
collapse (mean) gl, by(wave) 
save unmean.dta

use govmean.dta, clear
gen io="gov"
append using unmean.dta
ed
replace io="un" if io==""
sort io wave
save govunmean.dta, replace

use wvs1_7_weightedcountry_percgreatalot_wide.dta, clear   
append using govunmean.dta
drop if wave==1|wave==2
drop wave gl io

*manual copy-paste at end of dataset;
*then code average country=1000

/*
Germany, 276 (but not wave 3)
Japan, 392 
Poland, 616 (but not wave 3)
Russia, 643 (but not wave 3)
Turkey, 792 (but not wave 7)
US, 840
*/

save wvs1_7_weightedcountry_percgreatalot_wide.dta, replace

rename S003 country
rename S002 wave
sort country wave
keep if country==276|country==392|country==616|country==643|country==792|country==840|country==1000
replace country=1 if country==1000
sort country

save wvs1_7_weightedcountry_percgreatalot_wide_final.dta, replace


*Figure 2.1
******************************************

set scheme plotplain

xtset country wave
 
xtline glun, overlay ytitle(% a great deal or quite a lot of confidence) ///
xtitle("") title("Confidence in the UN") ylabel(0 "0%" .20 "20%" .40 "40%" .60 "60%" .80 "80%" 1.00 "100%") ///
xlabel(3 "1994-1998" 4 "1999-2004" 5 "2005-2009" 6 "2010-2014" 7 "2017-2020") ///
legend(order(1 "Average, all EVS/WVS countries" 2 "Germany" 3 "Japan" 4 "Poland" 5 "Russia" 6 "Turkey" 7 "United States")) ///
saving(Fig1a.gph, replace)

	xtline glgov, overlay ytitle(% a great deal or quite a lot of confidence) ///
	xtitle("") title("Confidence in government") ylabel(0 "0%" .20 "20%" .40 "40%" .60 "60%" .80 "80%" 1.00 "100%") ///
	xlabel(3 "1994-1998" 4 "1999-2004" 5 "2005-2009" 6 "2010-2014" 7 "2017-2020") ///
	legend(order(1 "Average, all EVS/WVS countries" 2 "Germany" 3 "Japan" 4 "Poland" 5 "Russia" 6 "Turkey" 7 "United States")) ///
	saving(Fig1b.gph, replace)




